<template>
  <div class="debug-env">
    <h2>环境变量调试</h2>
    <div class="env-info">
      <h3>当前环境变量:</h3>
      <p><strong>NODE_ENV:</strong> {{ nodeEnv }}</p>
      <p><strong>ENV_CONFIG:</strong> {{ envConfig }}</p>
      <p><strong>BASE_API:</strong> {{ baseApi }}</p>
      <p><strong>BASE_DOMAIN:</strong> {{ baseDomain }}</p>
    </div>

    <div class="test-section">
      <h3>测试登录API:</h3>
      <button :disabled="loading" @click="testLogin">{{ loading ? '测试中...' : '测试登录API' }}</button>
      <div v-if="result" class="result">{{ result }}</div>
    </div>
  </div>
</template>

<script>
import request from '@/utils/request'

export default {
  name: 'DebugEnv',
  data() {
    return {
      loading: false,
      result: ''
    }
  },
  computed: {
    nodeEnv() {
      return process.env.NODE_ENV
    },
    envConfig() {
      return process.env.ENV_CONFIG
    },
    baseApi() {
      return process.env.VUE_APP_BASE_API
    },
    baseDomain() {
      return process.env.BASE_DOMAIN
    }
  },
  methods: {
    async testLogin() {
      this.loading = true
      this.result = ''

      try {
        const response = await request({
          url: '/user/login',
          method: 'post',
          data: {
            username: 'admin',
            password: '123456'
          }
        })
        this.result = `成功: ${JSON.stringify(response, null, 2)}`
      } catch (error) {
        this.result = `错误: ${error.message || error}`
        console.error('登录测试失败:', error)
      }

      this.loading = false
    }
  }
}
</script>

<style scoped>
.debug-env {
  padding: 20px;
}

.env-info {
  background: #f5f5f5;
  padding: 15px;
  border-radius: 5px;
  margin-bottom: 20px;
}

.test-section {
  background: #e8f5e8;
  padding: 15px;
  border-radius: 5px;
}

.result {
  margin-top: 10px;
  padding: 10px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 3px;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
}

button {
  padding: 10px 20px;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 3px;
  cursor: pointer;
}

button:disabled {
  background: #ccc;
  cursor: not-allowed;
}
</style>
